export { };
const mongoose = require('mongoose');

const animalSchema = new mongoose.Schema({
  name: {
    type: String,
    minLength: 1,
    maxLength: 8,
    require: true
  },
  age: {
    type: Number,
    min: 0,
    max: 100,
    require: true
  },
  // 品种
  variety: {
    default: '猫',
    require: true,
    type: String,
    minLength: 1,
  },
  // 主人
  owner: {
    type: String,
    require: true,
    minLength: 1,
    maxLength: 10
  },
  phone: {
    type: String,
    require: true,
    validate: function (str: string) {
      return /^1\d{10}$/.test(str);
    }
  },
  regDate: {
    type: Date,
    default: new Date().toDateString()
  },
  color: String,
  email: {
    type: String,
    match: /^\S\w+@\w+\.\w+$/
  },
  likes: {
    type: [String],
    default: []
  }
});

const animal = mongoose.model('Animal', animalSchema);
module.exports = animal;